updating the ratings

packages

library(tidyverse) # CRAN v1.3.0 
<<<<<<< HEAD ======= >>>>>>> c61506b595d43f5813e182283920fd2db29fcc57
Registered S3 methods overwritten by 'dbplyr':
  method         from
  print.tbl_lazy     
  print.tbl_sql      
<<<<<<< HEAD
── Attaching packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
✓ ggplot2 3.3.2     ✓ purrr   0.3.4
✓ tibble  3.0.3     ✓ dplyr   1.0.0
✓ tidyr   1.1.0     ✓ stringr 1.4.0
✓ readr   1.3.1     ✓ forcats 0.5.0
── Conflicts ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()
======= ── Attaching packages ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ── ✓ ggplot2 3.3.1 ✓ purrr  0.3.4 ✓ tibble  3.0.1 ✓ dplyr  1.0.0 ✓ tidyr  1.1.0 ✓ stringr 1.4.0 ✓ readr  1.3.1 ✓ forcats 0.5.0 ── Conflicts ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ── x dplyr::filter() masks stats::filter() x dplyr::lag() masks stats::lag() >>>>>>> c61506b595d43f5813e182283920fd2db29fcc57
library(progress) # CRAN v1.2.2 
library(ggrepel)
library(lubridate)

Attaching package: ‘lubridate’

The following objects are masked from ‘package:base’:

    date, intersect, setdiff, union
library(conflicted) # CRAN v1.0.4
conflict_prefer("filter", "dplyr") 
[conflicted] Will prefer dplyr::filter over any other package
source("functions.R")
source("cleaning.R")
source("estimation.R")
source("graphs.R")
options(dplyr.summarise.inform = FALSE)

load up latest games and “pre” ratings

games <- read_rds("~/teaching/scoresway/rds/games.rds")
with_pre <- read_rds("wpre.rds")
with_pre
<<<<<<< HEAD

updated ratings

k <- 20
options(dplyr.summarise.inform = FALSE)
pb <- progress_bar$new(format = " progress [:bar] :percent eta: :eta", total = nrow(with_pre), width = 40)
with_pre %>% 
  mutate(rat=map2(this, pre, ~this_ratings(.x, .y, k, games))) %>% 
  mutate(post=map(rat, "r")) %>% 
  mutate(updates=map(rat, "d")) -> with_post
<<<<<<< HEAD

 progress [>-------------]   4% eta:  6s
 progress [>-------------]   5% eta:  6s
 progress [>-------------]   6% eta:  6s
 progress [>-------------]   8% eta:  6s
 progress [>-------------]   9% eta:  7s
 progress [>-------------]  10% eta:  7s
 progress [=>------------]  11% eta:  7s
 progress [=>------------]  13% eta:  7s
 progress [=>------------]  14% eta:  7s
 progress [=>------------]  15% eta:  7s
 progress [=>------------]  16% eta:  6s
 progress [=>------------]  18% eta:  6s
 progress [==>-----------]  19% eta:  6s
 progress [==>-----------]  20% eta:  6s
 progress [==>-----------]  22% eta:  6s
 progress [==>-----------]  23% eta:  6s
 progress [==>-----------]  24% eta:  6s
 progress [===>----------]  25% eta:  6s
 progress [===>----------]  27% eta:  6s
 progress [===>----------]  28% eta:  6s
 progress [===>----------]  29% eta:  6s
 progress [===>----------]  30% eta:  6s
 progress [===>----------]  32% eta:  6s
 progress [====>---------]  33% eta:  6s
 progress [====>---------]  34% eta:  5s
 progress [====>---------]  35% eta:  5s
 progress [====>---------]  37% eta:  5s
 progress [====>---------]  38% eta:  5s
 progress [====>---------]  39% eta:  5s
 progress [=====>--------]  41% eta:  5s
 progress [=====>--------]  42% eta:  5s
 progress [=====>--------]  43% eta:  5s
 progress [=====>--------]  44% eta:  5s
 progress [=====>--------]  46% eta:  4s
 progress [======>-------]  47% eta:  4s
 progress [======>-------]  48% eta:  4s
 progress [======>-------]  49% eta:  4s
 progress [======>-------]  51% eta:  4s
 progress [======>-------]  52% eta:  4s
 progress [======>-------]  53% eta:  4s
 progress [=======>------]  54% eta:  4s
 progress [=======>------]  56% eta:  4s
 progress [=======>------]  57% eta:  3s
 progress [=======>------]  58% eta:  3s
 progress [=======>------]  59% eta:  3s
 progress [========>-----]  61% eta:  3s
 progress [========>-----]  62% eta:  3s
 progress [========>-----]  63% eta:  3s
 progress [========>-----]  65% eta:  3s
 progress [========>-----]  66% eta:  3s
 progress [========>-----]  67% eta:  3s
 progress [=========>----]  68% eta:  3s
 progress [=========>----]  70% eta:  2s
 progress [=========>----]  71% eta:  2s
 progress [=========>----]  72% eta:  2s
 progress [=========>----]  73% eta:  2s
 progress [=========>----]  75% eta:  2s
 progress [==========>---]  76% eta:  2s
 progress [==========>---]  77% eta:  2s
 progress [==========>---]  78% eta:  2s
 progress [==========>---]  80% eta:  2s
 progress [==========>---]  81% eta:  2s
 progress [===========>--]  82% eta:  1s
 progress [===========>--]  84% eta:  1s
 progress [===========>--]  85% eta:  1s
 progress [===========>--]  86% eta:  1s
 progress [===========>--]  87% eta:  1s
 progress [===========>--]  89% eta:  1s
 progress [============>-]  90% eta:  1s
 progress [============>-]  91% eta:  1s
 progress [============>-]  92% eta:  1s
 progress [============>-]  94% eta:  1s
 progress [============>-]  95% eta:  0s
 progress [============>-]  96% eta:  0s
 progress [=============>]  97% eta:  0s
=======


 progress [--------------]   3% eta:  7s
 progress [>-------------]   4% eta: 10s
 progress [>-------------]   6% eta: 10s
 progress [>-------------]   7% eta: 11s
 progress [>-------------]   8% eta: 12s
 progress [>-------------]  10% eta: 12s
 progress [=>------------]  11% eta: 12s
 progress [=>------------]  13% eta: 13s
 progress [=>------------]  14% eta: 13s
 progress [=>------------]  15% eta: 13s
 progress [=>------------]  17% eta: 14s
 progress [==>-----------]  18% eta: 14s
 progress [==>-----------]  20% eta: 13s
 progress [==>-----------]  21% eta: 13s
 progress [==>-----------]  23% eta: 13s
 progress [==>-----------]  24% eta: 14s
 progress [===>----------]  25% eta: 13s
 progress [===>----------]  27% eta: 13s
 progress [===>----------]  28% eta: 13s
 progress [===>----------]  30% eta: 13s
 progress [===>----------]  31% eta: 13s
 progress [====>---------]  32% eta: 13s
 progress [====>---------]  34% eta: 13s
 progress [====>---------]  35% eta: 12s
 progress [====>---------]  37% eta: 12s
 progress [====>---------]  38% eta: 12s
 progress [=====>--------]  39% eta: 12s
 progress [=====>--------]  41% eta: 11s
 progress [=====>--------]  42% eta: 11s
 progress [=====>--------]  44% eta: 11s
 progress [=====>--------]  45% eta: 11s
 progress [======>-------]  46% eta: 11s
 progress [======>-------]  48% eta: 10s
 progress [======>-------]  49% eta: 10s
 progress [======>-------]  51% eta: 10s
 progress [======>-------]  52% eta:  9s
 progress [======>-------]  54% eta:  9s
 progress [=======>------]  55% eta:  9s
 progress [=======>------]  56% eta:  8s
 progress [=======>------]  58% eta:  8s
 progress [=======>------]  59% eta:  8s
 progress [=======>------]  61% eta:  7s
 progress [========>-----]  62% eta:  7s
 progress [========>-----]  63% eta:  7s
 progress [========>-----]  65% eta:  7s
 progress [========>-----]  66% eta:  6s
 progress [========>-----]  68% eta:  6s
 progress [=========>----]  69% eta:  6s
 progress [=========>----]  70% eta:  6s
 progress [=========>----]  72% eta:  5s
 progress [=========>----]  73% eta:  5s
 progress [=========>----]  75% eta:  5s
 progress [==========>---]  76% eta:  4s
 progress [==========>---]  77% eta:  4s
 progress [==========>---]  79% eta:  4s
 progress [==========>---]  80% eta:  4s
 progress [==========>---]  82% eta:  3s
 progress [===========>--]  83% eta:  3s
 progress [===========>--]  85% eta:  3s
 progress [===========>--]  86% eta:  3s
 progress [===========>--]  87% eta:  2s
 progress [===========>--]  89% eta:  2s
 progress [============>-]  90% eta:  2s
 progress [============>-]  92% eta:  2s
 progress [============>-]  93% eta:  1s
 progress [============>-]  94% eta:  1s
 progress [============>-]  96% eta:  1s
 progress [=============>]  97% eta:  1s
>>>>>>> c61506b595d43f5813e182283920fd2db29fcc57
 progress [=============>]  99% eta:  0s
 progress [==============] 100% eta:  0s
                                        
with_post
<<<<<<< HEAD

save

write_rds(with_post, "wpost.rds")

read

with_post <- read_rds("wpost.rds")

look at one

<<<<<<< HEAD
with_post %>% filter(league=="japan") %>% 
  unnest(post) %>% 
  select(team, rating, h) %>% arrange(desc(rating))

look at all

see post values sorted in tabs

since_hrs <- 24
with_post %>% 
  mutate(latest=map_dbl(updates, ~max(.$time_stamp))) %>% 
  mutate(since=(now()-as_datetime(latest))/dhours(1)) %>% 
  filter(since<=since_hrs) -> wp2
wp2
<<<<<<< HEAD

see post values sorted in tabs

# read_csv("wanted.txt") %>% pull(want) -> wants
# wants
# with_post <- read_rds("wpost.rds")
# with_post %>% filter(league %in% wants) %>%  # edit/remove slice
wp2 %>% 
  arrange(desc(league)) %>% 
  select(post, updates, league) %>% 
  pwalk(~display(..1, ..2, ..3)) # first input to pwalk can be a df

plot

# time_graph("england 2", with_post)
map(wp2$league, ~time_graph(., with_post))
<<<<<<< HEAD ======= >>>>>>> c61506b595d43f5813e182283920fd2db29fcc57
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
<<<<<<< HEAD
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
======= Joining, by = "team"
>>>>>>> c61506b595d43f5813e182283920fd2db29fcc57
[[1]]

[[2]]

[[3]]

[[4]]

[[5]]

[[6]]

[[7]]

[[8]]

[[9]]

<<<<<<< HEAD
[[10]]

[[11]]

[[12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